﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Util;
using Util.Domains;

namespace IterationLife.System.Models
{
    /// <summary>
    /// 验证码
    /// </summary>
    [Description("验证码")]
    public partial class VerificationCode : AggregateRoot<VerificationCode>
    {
        /// <summary>
        /// 初始化
        /// </summary>
        public VerificationCode() : this(Guid.Empty)
        {
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="id">标识</param>
        public VerificationCode(Guid id) : base(id)
        {
        }

        /// <summary>
        /// 安全手机
        /// </summary>
        [StringLength(20, ErrorMessage = "安全手机输入过长，不能超过20位")]
        public string Mobile { get; set; }
        /// <summary>
        /// 安全邮箱
        /// </summary>
        [StringLength(200, ErrorMessage = "安全邮箱输入过长，不能超过200位")]
        public string Email { get; set; }
        /// <summary>
        /// 过期时间
        /// </summary>
        [Required(ErrorMessage = "过期时间不能为空")]
        public DateTime ExpirationTime { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 验证码
        /// </summary>
        [StringLength(10, ErrorMessage = "验证码输入过长，不能超过10位")]
        public string Code { get; set; }
        /// <summary>
        /// 用途
        /// </summary>
        [StringLength(100, ErrorMessage = "用途输入过长，不能超过100位")]
        public string Purpose { get; set; }
        /// <summary>
        /// 是否已使用
        /// </summary>
        [Required(ErrorMessage = "是否已使用不能为空")]
        public bool IsUsed { get; set; }

        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions()
        {
            AddDescription("验证码编号", Id);
            AddDescription("安全手机", Mobile);
            AddDescription("安全邮箱", Email);
            AddDescription("过期时间", ExpirationTime);
            AddDescription("创建时间", CreationTime);
            AddDescription("验证码", Code);
            AddDescription("用途", Purpose);
            AddDescription("是否已使用", IsUsed.Description());
        }

        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges(VerificationCode newEntity)
        {
            AddChange("Id", "验证码编号", Id, newEntity.Id);
            AddChange("Mobile", "安全手机", Mobile, newEntity.Mobile);
            AddChange("Email", "安全邮箱", Email, newEntity.Email);
            AddChange("ExpirationTime", "过期时间", ExpirationTime, newEntity.ExpirationTime);
            AddChange("CreationTime", "创建时间", CreationTime, newEntity.CreationTime);
            AddChange("Code", "验证码", Code, newEntity.Code);
            AddChange("Purpose", "用途", Purpose, newEntity.Purpose);
            AddChange("IsUsed", "是否已使用", IsUsed, newEntity.IsUsed);
        }
    }
}
